package cn.xjt.hello;

/**
 * 例子：创建三个窗口买票，总票数为100张
 * 使用实现Runnable接口类的方式做的
 * @author xujiangtao
 * @create 2020-07-31-11:26
 */
public class WindowTest1 {
    public static void main(String[] args) {
        Windows w = new Windows();
        Thread t1=new Thread(w);
        t1.setName("线程一");
        Thread t2 = new Thread(w);
        t2.setName("线程二");
        Thread t3 = new Thread(w);
        t3.setName("线程三");
        t1.start();
        t2.start();
        t3.start();
    }
}
class Windows implements Runnable{
    private int ticket = 100;
    @Override
    public void run() {
        while (true)
        {
            if(ticket>0)
            {
                System.out.println(Thread.currentThread().getName()+"\t卖了"+(100-ticket)+"张票，剩余"+ticket+"张票");
                ticket--;
            }else{
                break;
            }
        }
    }
}
